<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="comm.util.QuikHashMap"%>
<%@page import="java.util.ArrayList"%>
<%@page import="quik.group.GroupProc"%>    
<%
	GroupProc group = new GroupProc();
	ArrayList lt = null;
	lt = group.getMembersGroupList(session.getAttribute("SESSION_MEMBER_SEQ").toString());
	int cntList = 0;
	String firstInnerGroupSeq = "";
	if(lt!=null)
		cntList = lt.size();
%>    

<!-- 메세지 입력창 -->

<%@page import="comm.util.RequestManager"%>
<%@page import="java.util.HashMap"%>
<div id="content-top"></div>
		<div id="lista" class="box">
	<%if(cntList>0){ %>
				<form method="post" action="./jsp/mypage/mypage_write_proc.jsp" enctype="multipart/form-data" class="message">
					<div>
						<input type="hidden" name="url" value="../../?content=mypage"/>
						<p><textarea name="article_content" rows="3"></textarea></p>
						
						받는이 : <select name="innergroup_seq">
							<%
							for(int i = 0;i<cntList;i++){
								QuikHashMap hm = new QuikHashMap();
								hm = (QuikHashMap)lt.get(i);
								if(i==0)
									firstInnerGroupSeq = hm.get("INNERGROUP_SEQ").toString();
							%>
							<option value="<%=hm.get("INNERGROUP_SEQ") %>"><%=hm.get("GROUP_NAME")%></option>
							<%}%>
						</select>				
						<input type="submit" value="보내기" style="width:310px;"/>
						<!-- 
						<input type="button" value="파일첨부(클릭시 레이어 뜨게 나중에)"/>
						 -->
					</div>
					<div><input type="button" value="자료 첨부하기" onclick="javascript:callAddDataForm(); " /></div>
					<div id="addData" style="display: none;">
						<div>파일 첨부 : <input type="file" name="file"/></div>
						<div>링크 : <input type="text" name="comment" value="http://"/></div>
					</div>
				</form>
	<%}else{ %>
	<div>가입한 그룹이 없습니다.</div>
	<%} %>
</div>
		<div id="content-bottom"></div>

<!-- 내 그룹의 글 -->
<%
	String curGroup = firstInnerGroupSeq;
	if(request.getParameter("group")!=null && request.getParameter("group").toString().length()>0){
		curGroup = request.getParameter("group").toString();
	}
%>
<div id="content-top"></div>
		<div id="lista" class="box">
		<span>메세지 보기 필터 : </span>
<select name="innergroup_seq" id="view_innergroup_select" onchange="javascript:onchangeHandler(this);">
	<%
		for(int i = 0;i<cntList;i++){
			QuikHashMap hm = new QuikHashMap();
			hm = (QuikHashMap)lt.get(i);
		%>
			<option value="<%=hm.get("INNERGROUP_SEQ")%>" <%if(hm.get("INNERGROUP_SEQ").toString().equals(curGroup)){%>selected="selected"<%}%>><%=hm.get("GROUP_NAME")%></option>
		<%}
		if(cntList<1){ %>
		<option>가입한 그룹이 없습니다.</option>
	<%} %>
</select>
<select name="page_size">
	<option value="15">15개씩</option>
<!--	<option value="20">20개씩</option>-->
<!--	<option value="30">30개씩</option>-->
<!--	<option value="50">50개씩</option>-->
</select>
</div>
		<div id="content-bottom"></div>
<%
	lt = null;

	HashMap rhm = RequestManager.getRequest(request);
	if(rhm.get("PAGE_NUM")!=null && rhm.get("PAGE_SIZE")!=null){
		lt = group.getMembersGroupArticleList(curGroup,session.getAttribute("SESSION_MEMBER_GROUPSEQ").toString(),
											Integer.parseInt(rhm.get("PAGE_SIZE").toString()),
											Integer.parseInt(rhm.get("PAGE_NUM").toString())
											);
	}else{
		lt = group.getMembersGroupArticleList(curGroup,session.getAttribute("SESSION_MEMBER_GROUPSEQ").toString(),15,1);
	}
	cntList = 0;
	if(lt!=null)
		cntList = lt.size();
%>
<div>
	<%if(lt!=null){
		for(int i = 0;i<cntList;i++){
			QuikHashMap hm = new QuikHashMap();
			hm = (QuikHashMap)lt.get(i);
			if(i==0)
				firstInnerGroupSeq = hm.get("INNERGROUP_SEQ").toString();
		%>
		<div id="content-top"></div>
		<div id="lista" class="box">
			<div><a href="<%=hm.get("INNERGROUP_SEQ") %>"><%=hm.get("GROUP_NAME")%></a></div>
			<div><%=hm.get("ARTICLE_CONTENT") %></div>
			<div><%=hm.get("MEMBER_NICK")%></div>
			<div><%=hm.get("ARTICLE_REGDATE")%></div>
		</div>
		<div id="content-bottom"></div>
		<%}
		}else{ %>
		<div>등록된 글이 없습니다.</div>
	<%} %>
</div>

<!-- 페이지 네비게이션 -->
	<div>
		<div>
			<%if(rhm.get("PAGE_NUM")!=null && rhm.get("PAGE_SIZE")!=null && Integer.parseInt(rhm.get("PAGE_NUM").toString()) > 1){ %>
				<a href="./?content=mypage&menu=group&page_num=<%=Integer.parseInt(rhm.get("PAGE_NUM").toString())-1%>&page_size=<%=rhm.get("PAGE_SIZE").toString() %>">이전페이지</a>
			<%}else{ %>
				<a title="첫번째페이지입니다.">이전페이지</a>
			<%} %>
		</div>
		<div>
			<%if(rhm.get("PAGE_NUM")!=null  && rhm.get("PAGE_SIZE")!=null && lt.size() < Integer.parseInt(rhm.get("PAGE_SIZE").toString())){ %>
				<a title="마지막페이지입니다.">다음페이지</a>
			<%}else if(rhm.get("PAGE_NUM")!=null && rhm.get("PAGE_SIZE")!=null){ %>
				<a href="./?content=mypage&menu=group&page_num=<%=Integer.parseInt(rhm.get("PAGE_NUM").toString())+1%>&page_size=<%=rhm.get("PAGE_SIZE").toString() %>">다음페이지</a>
			<%}else{ %>
				<a href="./?content=mypage&menu=group&page_num=2&page_size=15">다음페이지</a>
			<%} %>
		</div>
	</div>